package org.xiyu.yee.beacon_anti_phantom;

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.minecraft.server.level.ServerLevel;
import org.xiyu.yee.beacon_anti_phantom.event.ServerEventHandler;

public class Beacon_anti_phantom implements ModInitializer {

    @Override
    public void onInitialize() {

        // This method is invoked by the Fabric mod loader when it is ready
        // to load your mod. You can access Fabric and Common code in this
        // project.

        // Use Fabric to bootstrap the Common mod.
        Constants.LOG.info("Hello Fabric world!");
        CommonClass.init();
        
        // 注册服务器事件
        registerServerEvents();
    }
    
    private void registerServerEvents() {
        // 服务器tick事件
        ServerTickEvents.END_WORLD_TICK.register(this::onWorldTick);
        
        // 服务器启动事件
        ServerLifecycleEvents.SERVER_STARTED.register(server -> {
            ServerEventHandler.getInstance().onServerStarted();
            Constants.LOG.info("Beacon Anti-Phantom mod is now active on server!");
        });
    }
    
    private void onWorldTick(ServerLevel world) {
        ServerEventHandler.getInstance().onServerTick(world);
    }
}
